<?php
/** .-------------------------------------------------------------------
* |  Software: [HDCMS framework]
* |      Site: www.hdcms.com
* |-------------------------------------------------------------------
* |    Author: 向军 <2300071698@qq.com>
* |    WeChat: aihoudun
* | Copyright (c) 2012-2019, www.houdunwang.com. All Rights Reserved.
* '-------------------------------------------------------------------*/

namespace app\home\controller;


class Tissot extends Common {
    //动作
    public function index(){
    //此处书写代码...

		$gid=Q('gid');
	    $tissotData = Db::table('detail')->where('gid',$gid)->first();
	    $big=str_replace('，',',',$tissotData['big']);
	    $tissotData['big']=explode(',',$big);
	    View::with('tissotData',$tissotData);
		$goodsData=Db::table('goods')->join("detail","goods.gid","=","detail.gid")->where('goods.gid',$gid)->first();
//	    p($goodsData);die;
	    View::with('goodsData',$goodsData);

	    $tid = Db::table('goods')->where('gid',$gid)->pluck('tid');
	    //类型属性数据
	    $typeData = Db::table('type_attr')->where('class',1)->where('tid',$tid)->get();
	    foreach($typeData as $k=>$v){
		    $typeData[$k]['select'] = Db::table('goods_attr')
		                                ->where('taid',$v['taid'])
		                                ->where('gid',$gid)
		                                ->get();
	    }
	    View::with('typeData',$typeData);
	    $Data = Db::table('type_attr')->where('class',2)->where('tid',$tid)->get();
	    foreach($Data as $k=>$v){
		    $Data[$k]['select'] = Db::table('goods_attr')
		                                ->where('taid',$v['taid'])
		                                ->where('gid',$gid)
		                                ->get();
	    }
//	    p($Data);die;
	    View::with('Data',$Data);
	    return view();
    }
	//加入购物车
	public function addCart(){
		//获得商品表主键
		$gid = Q('post.gid');
		//获得当前商品数据
		$qian=array(" ","　","\t","\n","\r");
		$spec=str_replace($qian,'',Q('post.spec'));
		$spec=rtrim($spec,',');
		$GoodsData = Db::table('goods')->where('gid',$gid)->first();
//		p($GoodsData);die;
		//添加购物车使用 Cart::add() 方法实现，购物车中的数据会写入到 $_SESSION 超全局数组中。
		$data = [
			'id'  => $gid, // 商品 ID
			'name' =>  $GoodsData['gname'],// 商品名称
			'num' => Q('post.num'), // 商品数量
			'price'  => $GoodsData['shopprice'], // 商品价格
			'options' => $spec,// 其他参数如价格、颜色、可以为数组或字符串
			'pic'  => $GoodsData['pic']//图片
		];
		Cart::add($data); // 添加到购物车
	}

}
